package com.bilibili.liveremind.module.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.bilibili.liveremind.module.entity.UserLive;
import com.bilibili.liveremind.module.service.IUserLiveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/UserLive")
public class UserLiveController {

    @Autowired
    private IUserLiveService userLiveService;

    @GetMapping("/liveInfo")
    public Map<String,Object> liveInfo(String userId){
        LambdaQueryWrapper<UserLive> userLiveLambdaQueryWrapper = new LambdaQueryWrapper<>();
        userLiveLambdaQueryWrapper.eq(UserLive::getUserId,userId);
        userLiveLambdaQueryWrapper.eq(UserLive::getDeleteMark,0);
        userLiveLambdaQueryWrapper.orderByDesc(UserLive::getCreateDate);
        List<UserLive> userLiveList = userLiveService.list(userLiveLambdaQueryWrapper);
        Map<String,Object> resMap = new HashMap<>();
        resMap.put("data",userLiveList);
        return resMap;
    }

    @GetMapping("/updateStatus")
    public String updateStatus(String userLiveId){
        UserLive userLive = userLiveService.getById(userLiveId);
        if (userLive.getStatus() == 1){
            userLive.setStatus(0);
        }else if (userLive.getStatus() == 0){
            userLive.setStatus(1);
        }
        userLiveService.updateById(userLive);
        return "修改完成!";
    }

    @GetMapping("/deleteLive")
    public String deleteLive(String userLiveId){
        LambdaUpdateWrapper<UserLive> userLiveLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        userLiveLambdaUpdateWrapper.eq(UserLive::getId,userLiveId);
        userLiveLambdaUpdateWrapper.set(UserLive::getDeleteMark,1);
        userLiveService.update(userLiveLambdaUpdateWrapper);
        return "删除完成!";
    }



}
